<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var nums = [20, 4, 10, 15, 100, 88]
    nums.sort(function (item1, item2) {
      // return item1 - item2 // 升序
      return item2 - item1 // 降序
    })
    console.log(nums)
    console.log(nums.reverse()) // 反转

    var students = [
      { id: 100, name: 'why', age: 18 },
      { id: 101, name: 'kobe', age: 30 },
      { id: 102, name: 'james', age: 25 },
      { id: 103, name: 'why1', age: 22 },
    ]
    students.sort(function (item1, item2) {
      return item1.age - item2.age
    })
    console.log(students)

  </script>
</body>

</html>